module.exports = app => {
  const express = require('express');
  const router = express.Router();

  // 引入Swiper数据库模型
  const Swiper = require('../../models/Swiper')
  // 获取5条Swiper数据
  router.get('/Swiper', async (req, res) => {
    const model = await Swiper.find().limit(5)
    res.send(model)
  });
  // 创建Swiper数据
  router.post('/Swiper', async (req, res) => {
    const model = await Swiper.create(req.body)
    res.send(model)
  });
  // 修改Swiper数据
  router.put('/Swiper/:id', async (req, res) => {
    await Swiper.findByIdAndUpdate(req.params.id, req.body)
    res.send({
      success: true
    })
  });
  // 删除Swiper数据
  router.delete('/Swiper/:id', async (req, res) => {
    const model = await Swiper.findByIdAndDelete(req.params.id)
    console.log(model);
    res.send({
      success: true
    })
  });
  /* GET home page. */
  router.get('/', function (req, res) {
    res.send({
      title: 'Express'
    });
  });
  app.use('/admin', router)
}